package com.mdb.open.trade.feign.fallback;

import com.mdb.bc.api.data.ResultEx;
import com.mdb.bc.api.enums.ResultCode;
import com.mdb.open.common.enums.trade.type.RelationTypeEnum;
import com.mdb.open.trade.feign.CustomerClient;
import com.mdb.open.trade.feign.dto.cus.CustAllInfoDto;
import com.mdb.open.trade.feign.dto.cus.CustAndParentCodeDto;
import com.mdb.open.trade.feign.dto.cus.CustQueryDto;
import com.mdb.open.trade.feign.dto.cus.CustomerUpdateDto;
import com.mdb.open.trade.feign.vo.cus.CustAllDetailVo;
import com.mdb.open.trade.feign.vo.cus.CustBaseInfoVo;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * @author you.yichao
 * @Date 2019-11-11 19:35
 */
@Slf4j
@Component
public class CustomerClientFallback implements FallbackFactory<CustomerClient> {
    @Override
    public CustomerClient create(Throwable throwable) {

        log.error("调用客户服务[cnt-customer-service]发生异常", throwable);

        ResultEx result = ResultEx.makeResult(ResultCode.INVOKING_REMOTE_SERVICE, "调用客户服务发生未知异常");

        return new CustomerClient() {
            @Override
            public ResultEx<CustBaseInfoVo> saveCustInfoDirect(CustAllInfoDto infoDto) {
                result.setRetMsg("客户信息保存--直接生效异常");
                return result;
            }

            @Override
            public ResultEx updateCustBaseInfo(CustAllInfoDto infoDto) {
                result.setRetMsg("更新客户基本资料--直接生效异常");
                return result;
            }

            @Override
            public ResultEx<CustAllDetailVo> getCustAllInfo(CustAndParentCodeDto custAndParentCode) {
                result.setRetMsg("查询客户资料详情异常");
                return result;
            }

            @Override
            public ResultEx updateCustInfoGenerateOrder(@RequestBody CustomerUpdateDto customerUpdateDto) {
                result.setRetMsg("修改客户资料，生成工单异常");
                return result;
            }

            @Override
            public ResultEx<CustBaseInfoVo> getCustBaseInfo(CustQueryDto queryDto) {
                result.setRetMsg("查询客户资料基础详情异常");
                return result;
            }

            @Override
            public ResultEx<CustBaseInfoVo> getRelationCustomerInfoByParentCode(String parentCode, RelationTypeEnum relationTypeEnum) {
                result.setRetMsg("查询客户资料基础详情异常");
                return result;
            }

        };
    }
}
